<template>
  <data-v-chart style="height: 100%" @set-opt="onSet"></data-v-chart>
</template>

<script>
import optionFromData from "./opt";
import option2FromData from "./opt2";

export default {
  name: "data-v-pic-bar",
  props: {
    type: {
      type: [Number, String],
      default: 1
    }
  },
  methods: {
    onSet(chart) {
      this.setChart1(chart);

      if (this.type == 1) {
        this.setChart1(chart);
      } else if (this.type == 2) {
        this.setChart2(chart);
      }
    },

    setChart1(chart) {
      let data = range(1, 17, function(v) {
        return v + Math.random() * 10;
      });
      let opt = optionFromData(data);
      chart.setOption(opt);
    },

    setChart2(chart) {
      let data = range(1, 8, function(v) {
        return v +  (Math.random() * 10).toFixed(2) * 1;
      });
      let opt = option2FromData(data);
      chart.setOption(opt);
    }
  }
};
</script>
